package com.yingpai.fitness.dvp_2_0.main.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lzy.okgo.model.Response;
import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.adapter.BaseAdapterHelper;
import com.yingpai.fitness.dvp_2_0.common.adapter.QuickAdapter;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.callback.Callback;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.request.RequestType;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Url;
import com.yingpai.fitness.entity.QuestionBean;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ASUS on 2018/12/5.
 */

public class HelpActivity extends CommonActivity {
    @BindView(R.id.listview)
    ListView listview;
    private QuickAdapter<QuestionBean> quickAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.help_web_view_activity);
    }

    @Override
    protected void initView() {
        setTitle("常见问题");
        quickAdapter = new QuickAdapter<QuestionBean>(this,R.layout.item_question) {
            @Override
            protected void convert(BaseAdapterHelper helper, QuestionBean item) {
                helper.setText(R.id.title,item.getName());
            }
        };

        listview.setAdapter(quickAdapter);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putString("id",quickAdapter.getItem(position).getId());
                startActivity(QuestionDetailActivity.class,bundle);
            }
        });

    }

    @Override
    protected void initData() {
        showDialog(this,null);
        finalOkGo.request(RequestType.GETLIST, Contacts.HOST_SERVER + Url.GET_QUESTION, null, Url.GET_QUESTION, new Callback<QuestionBean>() {
            @Override
            public void onSuccess(QuestionBean questionBean) {

            }

            @Override
            public void onListSuccess(List<QuestionBean> t) {
                super.onListSuccess(t);
                dismissDialog();
                quickAdapter.clear();
                quickAdapter.addAll(t);
                quickAdapter.notifyDataSetChanged();
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                dismissDialog();
            }
        });
    }

    @Override
    @OnClick({})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {

        }
    }
}
